//
//  MKUIAnimation.h
//  MKUI
//  自定义动画效果,自持有，动画结束时，自动释放
//  Created by 苏尚进 on 2025/6/23.
//  Copyright © 2025 moon. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef CGFloat (^MKUIAnimationEasingFunction)(CGFloat);
@interface MKUIAnimation : NSObject
@property(nonatomic,assign) NSTimeInterval duration;//单次动画的时长，单位秒
@property(nonatomic,assign) NSTimeInterval delay;//延迟开始时间，单位秒
@property(nonatomic,copy,nullable) void(^animationsBlock)(CGFloat progress);//动画执行过程，progress为进度百分比值
@property(nonatomic,copy,nullable) void(^completionBlock)(BOOL finished);//结束结束回调，finished代表动画是否完整地执行
@property(nonatomic,copy,nullable) MKUIAnimationEasingFunction easingFunction;//缓动函数
@property(nonatomic,assign) NSInteger repeatCount;//重复次数,默认为1.<=0代表无限
@property(nonatomic,assign) BOOL autoreverse;//是否自动回放，默认为NO.如果设置回放，将在duration时间内，完成一来一回的动画播放
@property(nonatomic,readonly) BOOL isAnimation;//是否动画中
/// 开始动画
- (void)beginAnimation;

/// 取消动画
- (void)cancelAnimation;
@end
NS_ASSUME_NONNULL_END

NS_ASSUME_NONNULL_BEGIN

@interface MKUIAnimationEasingObject : NSObject
@property(nonatomic,readonly) MKUIAnimationEasingFunction In;
@property(nonatomic,readonly) MKUIAnimationEasingFunction Out;
@property(nonatomic,readonly) MKUIAnimationEasingFunction InOut;
@property(nonatomic,readonly) MKUIAnimationEasingFunction OutIn;
- (CGFloat)baseInFunction:(CGFloat)p;
@end
//y=x
@interface MKUIAnimationEasingLiner : MKUIAnimationEasingObject
@property(nonatomic,class,readonly) __kindof MKUIAnimationEasingObject* Function;
@end
//y=x^(n)
@interface MKUIAnimationEasingPower : MKUIAnimationEasingObject
@property(nonatomic,assign) NSInteger power;
@property(nonatomic,class,readonly) MKUIAnimationEasingPower *(^Function)(NSInteger power);
@end
//2指数级：y=2^(10(x-1))
@interface MKUIAnimationEasingExponential : MKUIAnimationEasingObject
@property(nonatomic,class,readonly) __kindof MKUIAnimationEasingObject* Function;
@end
//回退：y = x^3-x*sin(x*pi)
@interface MKUIAnimationEasingBack : MKUIAnimationEasingObject
@property(nonatomic,class,readonly) __kindof MKUIAnimationEasingObject* Function;
@end
//阻尼振荡效果,开始和结束都为0：y=-A*e^(-d*x)*cos(n*PI*x+0.5*PI)
@interface MKUIAnimationEasingBounce: MKUIAnimationEasingObject
@property(nonatomic,assign) NSInteger bounceCount;//弹跳的次数,默认为2
@property(nonatomic,assign) BOOL oscillate;//是否来回振荡，YES：来回振荡，NO：反弹。默认为NO
+ (instancetype)functionWithBounceCount:(NSInteger)bounceCount;
@end

NS_ASSUME_NONNULL_END
